import java.util.Random;

public class TestDemo {
    public static int[] array = null;
    public static int Count;

    public static void main(String[] args) throws InterruptedException {
        array = new int[1000_0000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(101);
        }

        long begin = System.currentTimeMillis();
        Thread t1 = new Thread(() -> {
            synchronized(TestDemo.class) {
                for (int i = 0; i < array.length; i += 2) {
                    Count += array[i];
                }
            }
        });


        Thread t2 = new Thread(() -> {
            synchronized(TestDemo.class) {
                for (int i = 1; i < array.length; i += 2) {
                    Count += array[i];
                }
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        long end = System.currentTimeMillis();
        System.out.println(Count);
        System.out.println((end - begin) + "ms");
    }
}
